package com.prototype.demo03;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * 原型角色:
 * 猴孙是可复制的,复制出来的每个猴孙都持有金箍棒
 */
@Data
public class Monkey implements Cloneable {
    private LocalDateTime birthday;
    private int weight;
    private int height;
    private GoldRingedStaff staff;

    public Monkey(){
        this.birthday = LocalDateTime.now();
        this.staff = new GoldRingedStaff();
    }

    // 子类重写Object#clone(),并处理了异常,不再向外抛出
    @Override
    public Object clone()  {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    }
}
